package com.hui.server.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hui.server.config.redis.RedisCacheConfig;
import com.hui.server.entity.MenuRole;
import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author hui
 * @since 2022-03-31
 */

//@CacheNamespace(implementation = RedisCacheConfig.class)
public interface MenuRoleMapper extends BaseMapper<MenuRole> {



    @Select("select * from t_menu_role ORDER BY rid")
    List<MenuRole> getAll();

    /**
     * 更新角色菜单，根据角色ID插入菜单id
     * <p/>注解形式的动态SQL必须要用 script 标签包裹起来
     * @param rid
     * @param mids
     * @return
     */
    @Insert("<script> " +
            "insert into t_menu_role(mid,rid) values" +
            "<foreach collection=\"mids\" item=\"mid\" separator=\",\">" +
            "(#{mid},#{rid})" +
            "</foreach>" +
            "</script>")
    Integer insertRecord(@Param("rid")Integer rid, @Param("mids") Integer[] mids);
}
